package com.design.proxy;

import com.design.ICacheAdapter;

import java.lang.reflect.Proxy;

/**
 * 代理类
 * @author ytj
 * @date 2021/12/24
 */
public class JdkProxy {

    public static <T> T getProxy(Class classInterface, ICacheAdapter iCacheAdapter){
        Class clazz=classInterface.getInterfaces()[0];
        ClassLoader classLoader=Thread.currentThread().getContextClassLoader();
        return (T)Proxy.newProxyInstance(classLoader,new Class[]{clazz},new JdkInvocationHandle(iCacheAdapter));
    }
}
